package com.red.controller;

import com.red.pojo.Result;
import com.red.pojo.entity.House;
import com.red.pojo.model.LoginUser;
import com.red.service.IHousePushService;
import com.red.util.HttpStatusUtil;
import com.red.util.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HousePushController {

    @Autowired
    private IHousePushService housePushService;

    @GetMapping("/public/push")
    public Result push(HttpServletRequest request) {
        int userId;

        if (request.getHeader("token").isEmpty()) {
            userId = 1;
        } else {
            LoginUser loginUser = JWTUtil.getLoginUser(request);
            userId = loginUser.getUserID();
        }

        return housePushService.push(userId, 8);
    }
}